package com.yanqu.road.server.cmd.activity.bowart;

import com.yanqu.road.entity.activity.bowart.BowArtUserData;
import com.yanqu.road.pb.activity.BowArtProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.bowart.BowArtModule;
import com.yanqu.road.server.manger.activity.bowart.BowArtMgr;
import com.yanqu.road.server.manger.activity.bowart.TargetBehavior;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_BOW_ART_ACTIVITY_IN_PREPARE, desc = "准备")
public class BowArtPrepareCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(BowArtMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!BowArtMgr.activityInTime()){
            ret = GameErrorCode.E_BOW_ART_ACTIVITY_NO_IN_TIME;
            return;
        }
        ret = player.getModule(BowArtModule.class).prepare();
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            BowArtProto.BowArPrepareRespMsg.Builder respMsg = BowArtProto.BowArPrepareRespMsg.newBuilder();
            respMsg.setRet(ret);
            BowArtUserData userData = player.getModule(BowArtModule.class).getUserData();
            TargetBehavior behavior  = BowArtMgr.getTargetBehaviorList().get(userData.getCurTargetIndex());
            respMsg.setCurTargetType(behavior.getTargetType());
            respMsg.setCurTargetDistanceIdx(behavior.getDistanceIdx());
            player.sendPacket(Protocol.U_BOW_ART_ACTIVITY_IN_PREPARE, respMsg);
        }
    }
}
